import { Component } from 'react';
import { AtModal  } from "taro-ui"
import Taro from '@tarojs/taro';
import { View, Button,Text } from '@tarojs/components'
import './index.scss'

interface Props {
	isOpen?:boolean
}
export default class Authorization extends Component<Props, any> {

    constructor(props) {
        super(props)
				this.state = {
					open: false,
				}
    }

    UNSAFE_componentWillMount() {
		}

    componentDidMount() {
			let {isOpen} = this.props
			this.setState({
				open:isOpen
			})
		 }

    UNSAFE_componentWillReceiveProps(nextProps, nextContext) {
			let {isOpen} = nextProps
			this.setState({
				open:isOpen
			})
		}

    componentWillUnmount() { }

    componentDidShow() {

		 }

    componentDidHide() { }

    componentDidCatchError() { }

    componentDidNotFound() { }


		cancelAgreementModal = () => {
			// Taro.showToast({
			// 		title: '您取消了授权',
			// 		icon: 'none',
			// 		duration: 2000
			// })
			Taro.exitMiniProgram({
				success:(res)=>{
					console.log('res',res)
				},
				fail:(err)=>{
					console.log('err',err)
				},

			})
	}

	goWxAgreement = ()=>{
		wx.openPrivacyContract({
			success: (res) => {
					console.log('打开隐私协议成功', res)
			}, // 打开成功
			fail: (res) => {
					console.error('隐私协议打开失败', res)
			}, // 打开失败
			complete: () => { }
	})
}
 handleClickConfirm = () => {
	this.setState({
		open:false
	})
}
	handleAgreePrivacyAuthorization=()=> {

    // 用户点击同意按钮后
    // 用户点击同意后，开发者调用 resolve({ buttonId: 'agree-btn', event: 'agree' })  告知平台用户已经同意，参数传同意按钮的id
    // 用户点击拒绝后，开发者调用 resolve({ event:'disagree' }) 告知平台用户已经拒绝
  }

	render() {
			const {
				open
			} = this.state

			return (
				<AtModal
					isOpened={open}
					onClose={()=>this.cancelAgreementModal()}
					closeOnClickOverlay={false}>
					<View className='privacy-warp'>
				<View className='privacy-view'>
					<View>
						<View className='logo'></View>
						<View className="privacy-title">温馨提示</View>
					</View>
					<View className='privacy-des'>
					感谢您的支持与关注，我们深知个人信息对您的重要性，我们将按相关法律法规要求，尽力保护您的个人信息安全可控。在使用集群车宝服务前，请您务必同意
					<Text className="privacy-link" onClick={()=>this.goWxAgreement()}>《集群车宝隐私保护指引》</Text>和<Text onClick={() => { Taro.navigateTo({ url: '/pages/user/agreement/index' }) }} className='privacy-link'>《集群车宝协议》</Text>。如您不同意，很遗憾我们将无法继续为您提供服务。
					</View>
									<View>

											<Button className='privac-btn' id="agree-btn" openType={"agreePrivacyAuthorization" as any} bindagreeprivacyauthorization={()=>this.handleAgreePrivacyAuthorization()} onClick={()=>this.handleClickConfirm()}>同意，并继续</Button>
											<View onClick={()=>this.cancelAgreementModal()} className='privac-no'>不同意，并退出</View>
									</View>
					</View>
				</View>
			</AtModal>

			)
	}
}
